package model;


import static org.junit.Assert.*;

import java.awt.Color;

import junit.framework.Assert;

import org.bushe.swing.event.EventBus;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import constants.Events;

import model.playingfield.PlayingField;

/**
 * This test asserts that, given a MOVE event, Rules will perform the 
 * correct operations and update the state info in an appropriate way.
 * @author christopher
 *
 */
public class RulesTest2 {
	
	Model model;
	Player[] players;
	
	@Before
	public void setUp() throws Exception {
	
	Player p1 = new Player("Nils", Color.black, 0); 
	Player p2 = new Player("Mils", Color.blue, 1); 
	Player p3 = new Player("Wils", Color.red, 2);
	Player p4 = new Player("Kils", Color.green, 3);
	
	Player[] playersSet = {p1, p2, p3, p4};
	players = playersSet;
	
	/*
	 * Initiate the model, and simulate that a NEWGAME event has been called,
	 * with the above players as input.
	 */
	model = new Model();	
	}
	
	@Test
	public void testCheckPieces() throws Exception {
		
		boolean fail = false;
		
		//EventBus.publish(Events.NEWGAME.toString(), players); //THIS
		model.newGameEvent(Events.NEWGAME.toString(), players); 
				
		PlayingField field = model.getPlayingField();
		if(field == null){ 
			Assert.fail("PLAYINGFIELD IS NULL");
		}
		field.movePiece(56, 1);
		//Integer[][] locationsBefore = field.getPieceLocations();
		
		EventBus.publish(Events.DICETHROW.toString(), 1);
		EventBus.publish(Events.MOVE.toString(), 56);
		
		Integer[][] locationsAfter= model.getPlayingField().getPieceLocations();
						
		assertTrue(locationsAfter[0][0] == 1);
	}

	@After
	public void tearDown() throws Exception {
		model = null;
	}

}

